/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.google.code.japidiff;

import org.objectweb.asm.Attribute;

public class JavaField {

	private final int access;
	private final String name;
	private final String desc;
	private final String signature;
	private final Object value;
	private Attribute[] attributes;
	private JavaAnnotation[] annotations = new JavaAnnotation[0];

	public JavaField(int access, String name, String desc, String signature, Object value) {
		this.access = access;
		this.name = name;
		this.desc = desc;
		this.signature = signature;
		this.value = value;
	}

	public int getAccess() {
		return access;
	}

	public String getName() {
		return name;
	}

	public String getDesc() {
		return desc;
	}

	public String getSignature() {
		return signature;
	}

	public Object getValue() {
		return value;
	}

	public Attribute[] getAttributes() {
		return attributes;
	}

	public JavaAnnotation[] getAnnotations() {
		return annotations;
	}
	
	public void addAttribute(Attribute attr) {
		if (attributes == null) {
			attributes = new Attribute[] { attr };
		} else {
			Attribute[] old = attributes;
			attributes = new Attribute[old.length + 1];
			for (int i = 0; i < old.length; i++) {
				attributes[i] = old[i];
			}
			attributes[old.length] = attr;
		}
	}
	
	public void addAnnotation(JavaAnnotation annotation) {
		JavaAnnotation[] old = annotations;
		annotations = new JavaAnnotation[old.length + 1];
		for (int i = 0; i < old.length; i++) {
			annotations[i] = old[i];
		}
		annotations[old.length] = annotation;
	}

}
